package com.hsjk.szwj.module.train.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.hsjk.szwj.framework.common.exception.ServiceException;
import com.hsjk.szwj.framework.common.exception.enums.GlobalErrorCodeConstants;
import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.hsjk.szwj.framework.security.core.util.SecurityFrameworkUtils;
import com.hsjk.szwj.framework.tenant.core.aop.TenantIgnore;
import com.hsjk.szwj.module.train.controller.admin.dto.QuestionInitDTO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminInitPersonalPaperVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminInitStandardPaperVO;
import com.hsjk.szwj.module.train.controller.app.vo.chapter.AppMemberErrorQuestionChapterRespVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppMemberActionRecordReqVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppMemberCollectIdsReqVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppMemberErrorIdsReqVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppMemberPaperListReqVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppMemberPaperRecordPageReqVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppMemberPaperRecordPageRespVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppMemberPaperRecordReqVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppMemberPaperRecordRespVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppMemberPaperSummaryReqVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppMemberPaperSummaryRespVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppQuestionActionRecordReqVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppQuestionChapterListRespVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppQuestionListRespVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppQuestionPageRespVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppQuestionSetPageReqVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppQuestionTagPageReqVO;
import com.hsjk.szwj.module.train.controller.app.vo.question.AppStandardPaperQuestionRespVO;
import com.hsjk.szwj.module.train.convert.QuestionConvert;
import com.hsjk.szwj.module.train.dal.dataobject.config.TenantRegionConfigDO;
import com.hsjk.szwj.module.train.dal.dataobject.question.MemberPaperErrorRecordDO;
import com.hsjk.szwj.module.train.dal.dataobject.question.MemberPaperRecordDO;
import com.hsjk.szwj.module.train.dal.dataobject.question.MemberQuestionRecordDO;
import com.hsjk.szwj.module.train.dal.dataobject.question.PersonalPaperDO;
import com.hsjk.szwj.module.train.dal.dataobject.question.QuestionChapterDO;
import com.hsjk.szwj.module.train.dal.dataobject.question.QuestionDO;
import com.hsjk.szwj.module.train.dal.dataobject.question.QuestionKnowledgeDO;
import com.hsjk.szwj.module.train.dal.dataobject.question.QuestionKnowledgeMappingDO;
import com.hsjk.szwj.module.train.dal.dataobject.question.QuestionTagDO;
import com.hsjk.szwj.module.train.dal.dataobject.question.QuestionTagMappingDO;
import com.hsjk.szwj.module.train.dal.dataobject.question.StandardPaperDO;
import com.hsjk.szwj.module.train.dal.mysql.config.ITenantRegionConfigMapper;
import com.hsjk.szwj.module.train.dal.mysql.question.IInitPersonalPaperMapper;
import com.hsjk.szwj.module.train.dal.mysql.question.IInitStandardPaperMapper;
import com.hsjk.szwj.module.train.dal.mysql.question.IMemberPaperRecordMapper;
import com.hsjk.szwj.module.train.dal.mysql.question.IMemberQuestionRecordMapper;
import com.hsjk.szwj.module.train.dal.mysql.question.IPersonalPaperMapper;
import com.hsjk.szwj.module.train.dal.mysql.question.IQuestionChapterMapper;
import com.hsjk.szwj.module.train.dal.mysql.question.IQuestionKnowledgeMapper;
import com.hsjk.szwj.module.train.dal.mysql.question.IQuestionKnowledgeMappingMapper;
import com.hsjk.szwj.module.train.dal.mysql.question.IQuestionMapper;
import com.hsjk.szwj.module.train.dal.mysql.question.IQuestionTagMapper;
import com.hsjk.szwj.module.train.dal.mysql.question.IQuestionTagMappingMapper;
import com.hsjk.szwj.module.train.dal.mysql.question.IStandardPaperMapper;
import com.hsjk.szwj.module.train.enums.CarTypeEnum;
import com.hsjk.szwj.module.train.enums.QuestionTypeEnum;
import com.hsjk.szwj.module.train.enums.SubjectEnum;
import com.hsjk.szwj.module.train.service.IQuestionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/08/19 00:51
 **/
@Service
@Slf4j
public class QuestionServiceImpl implements IQuestionService {

    @Resource
    private IQuestionMapper questionMapper;

    @Resource
    private IQuestionChapterMapper chapterMapper;

    @Resource
    private IQuestionKnowledgeMapper knowledgeMapper;

    @Resource
    private IQuestionTagMapper tagMapper;

    @Resource
    private IQuestionTagMappingMapper questionTagMappingMapper;

    @Resource
    private IQuestionKnowledgeMappingMapper knowledgeMappingMapper;

    @Resource
    private IInitStandardPaperMapper iInitStandardPaperMapper;

    @Resource
    private IStandardPaperMapper standardPaperMapper;

    @Resource
    private IInitPersonalPaperMapper iInitPersonalPaperMapper;

    @Resource
    private IPersonalPaperMapper personalPaperMapper;

    @Resource
    private IMemberQuestionRecordMapper memberQuestionRecordMapper;

    @Resource
    private IMemberPaperRecordMapper memberPaperRecordMapper;

    @Resource
    private ITenantRegionConfigMapper tenantRegionConfigMapper;

    @Override
    public void questionInit(List<QuestionInitDTO> dtoList) {
        int sort = 1;
        for (QuestionInitDTO dto : dtoList) {
            QuestionDO questionDO = dto.getQuestionDO();
            questionDO.setSortNo(sort);
            questionDO.setTenantId(1691354060659232768L);
            QuestionChapterDO chapterByCode = chapterMapper
                    .getChapterOnly(dto.getChapterNo(), dto.getCarType(), dto.getSubject());
            if (ObjectUtil.isNotNull(chapterByCode)) {
                questionDO.setChapterId(chapterByCode.getId());
            }
            int insert = questionMapper.insert(questionDO);
            List<String> tagList = dto.getTagList();
            for (String tagCode : tagList) {
                QuestionTagMappingDO questionTagMappingDO = new QuestionTagMappingDO();
                questionTagMappingDO.setQuestionId(questionDO.getId());
                QuestionTagDO tagDO = tagMapper.getTagByCode(tagCode);
                questionTagMappingDO.setQuestionTagId(tagDO.getId());
                questionTagMappingDO.setTenantId(1691354060659232768L);
                questionTagMappingMapper.insert(questionTagMappingDO);
            }
            List<String> knowpointCodeList = dto.getKnowpointCodeList();
            for (String code : knowpointCodeList) {
                QuestionKnowledgeDO knowledgeByCode = knowledgeMapper.getKnowledgeByCode(code);
                QuestionKnowledgeMappingDO knowledgeMappingDO = new QuestionKnowledgeMappingDO();
                knowledgeMappingDO.setQuestionKnowledgeId(knowledgeByCode.getId());
                knowledgeMappingDO.setQuestionId(questionDO.getId());
                knowledgeMappingDO.setTenantId(1691354060659232768L);
                knowledgeMappingMapper.insert(knowledgeMappingDO);
            }
            sort++;
        }
    }

    @Override
    public void initStandardPaper() {
        int limit = 10;
        for (int i = 1; i <= limit; i++) {
            initStandardPaperForCarAndSubject1(i);
            initStandardPaperForCarAndSubject4(i);
            initStandardPaperForMotoAndSubject1(i);
            initStandardPaperForMotoAndSubject4(i);
        }
    }

    @Override
    public void initPersonalPaper(Long memberId, Integer carType, Integer subject) {
        if (CarTypeEnum.CAR.getType().equals(carType)) {
            if (SubjectEnum.ONE.getType().equals(subject)) {
                initPersonalPaperForCarAndSubject1(memberId);
            } else if (SubjectEnum.FOUR.getType().equals(subject)) {
                initPersonalPaperForCarAndSubject4(memberId);
            }
        } else if (CarTypeEnum.MOTO.getType().equals(carType)) {
            if (SubjectEnum.ONE.getType().equals(subject)) {
                initPersonalPaperForMotoAndSubject1(memberId);
            } else if (SubjectEnum.FOUR.getType().equals(subject)) {
                initPersonalPaperForMotoAndSubject4(memberId);
            }
        }
    }

    @Override
    public void initPersonalPaperForCarAndSubject1(Long memberId) {
        int carType = CarTypeEnum.CAR.getType();
        int subject = SubjectEnum.ONE.getType();
        List<AdminInitPersonalPaperVO> allList = new ArrayList<>();
        int chapterCode1 = 1;
        int chapterCode1Limit = 20;
        List<AdminInitPersonalPaperVO> chapterCode1List =
                iInitPersonalPaperMapper.listInitCarPersonalPaper(memberId, carType, subject,
                        chapterCode1, QuestionTypeEnum.JUDGE.getType(), chapterCode1Limit);
        if (CollUtil.isNotEmpty(chapterCode1List)) {
            allList.addAll(chapterCode1List);
        }

        int chapterCode5 = 5;
        int chapterCode5Limit = 10;
        List<AdminInitPersonalPaperVO> chapterCode5List =
                iInitPersonalPaperMapper.listInitCarPersonalPaper(memberId, carType, subject,
                        chapterCode5, QuestionTypeEnum.JUDGE.getType(), chapterCode5Limit);
        if (CollUtil.isNotEmpty(chapterCode5List)) {
            allList.addAll(chapterCode5List);
        }

        int chapterCode6 = 6;
        int chapterCode6Limit = 10;
        List<AdminInitPersonalPaperVO> chapterCode6List =
                iInitPersonalPaperMapper.listInitCarPersonalPaper(memberId, carType, subject,
                        chapterCode6, QuestionTypeEnum.JUDGE.getType(), chapterCode6Limit);
        if (CollUtil.isNotEmpty(chapterCode6List)) {
            allList.addAll(chapterCode6List);
        }

        int chapterCode2 = 2;
        int chapterCode2Limit = 25;
        List<AdminInitPersonalPaperVO> chapterCode2List =
                iInitPersonalPaperMapper.listInitCarPersonalPaper(memberId, carType, subject,
                        chapterCode2, QuestionTypeEnum.SINGLE.getType(), chapterCode2Limit);
        if (CollUtil.isNotEmpty(chapterCode2List)) {
            allList.addAll(chapterCode2List);
        }

        int chapterCode3 = 3;
        int chapterCode3Limit = 25;
        List<AdminInitPersonalPaperVO> chapterCode3List =
                iInitPersonalPaperMapper.listInitCarPersonalPaper(memberId, carType, subject,
                        chapterCode3, QuestionTypeEnum.SINGLE.getType(), chapterCode3Limit);
        if (CollUtil.isNotEmpty(chapterCode3List)) {
            allList.addAll(chapterCode3List);
        }

        int chapterCode4 = 4;
        int chapterCode4Limit = 10;
        List<AdminInitPersonalPaperVO> chapterCode4List =
                iInitPersonalPaperMapper.listInitCarPersonalPaper(memberId, carType, subject,
                        chapterCode4, QuestionTypeEnum.SINGLE.getType(), chapterCode4Limit);
        if (CollUtil.isNotEmpty(chapterCode4List)) {
            allList.addAll(chapterCode4List);
        }
        if (CollUtil.isNotEmpty(allList)) {
            List<PersonalPaperDO> doList = new ArrayList<>();
            for (AdminInitPersonalPaperVO vo : allList) {
                PersonalPaperDO paperDO = new PersonalPaperDO();
                paperDO.setCarType(carType);
                paperDO.setSubject(vo.getSubject());
                paperDO.setQuestionId(vo.getQuestionId());
                paperDO.setMemberId(memberId);
                doList.add(paperDO);
            }
            if (CollUtil.isNotEmpty(doList)) {
                personalPaperMapper.insertBatch(doList);
            }
        }
    }

    @Override
    public void initStandardPaperForCarAndSubject1(Integer batchNum) {
        Integer carType = CarTypeEnum.CAR.getType();
        Integer subject = SubjectEnum.ONE.getType();
        List<AdminInitStandardPaperVO> allList = new ArrayList<>();
        //先判断是否有地方题
        TenantRegionConfigDO tenantRegionConfigDO = tenantRegionConfigMapper.selectOne(new LambdaQueryWrapperX<TenantRegionConfigDO>()
                .eq(TenantRegionConfigDO::getSubject, subject));
        if (ObjectUtil.isNotNull(tenantRegionConfigDO)) {
            int chapterCode1 = 1;
            int chapterCode1JudgeLimit = 14;
            List<AdminInitStandardPaperVO> chapterCode1JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode1,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode1JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode1JudgeList)) {
                allList.addAll(chapterCode1JudgeList);
            }
            int chapterCode1SingleLimit = 21;
            List<AdminInitStandardPaperVO> chapterCode1SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode1,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode1SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode1SingleList)) {
                allList.addAll(chapterCode1SingleList);
            }

            int chapterCode2 = 2;
            int chapterCode2JudgeLimit = 14;
            List<AdminInitStandardPaperVO> chapterCode2JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode2,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode2JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode2JudgeList)) {
                allList.addAll(chapterCode2JudgeList);
            }
            int chapterCode2SingleLimit = 22;
            List<AdminInitStandardPaperVO> chapterCode2SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode2,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode2SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode2SingleList)) {
                allList.addAll(chapterCode2SingleList);
            }

            int chapterCode3 = 3;
            int chapterCode3JudgeLimit = 3;
            List<AdminInitStandardPaperVO> chapterCode3JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode3,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode3JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode3JudgeList)) {
                allList.addAll(chapterCode3JudgeList);
            }
            int chapterCode3SingleLimit = 6;
            List<AdminInitStandardPaperVO> chapterCode3SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode3,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode3SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode3SingleList)) {
                allList.addAll(chapterCode3SingleList);
            }

            int chapterCode4 = 4;
            int chapterCode4JudgeLimit = 3;
            List<AdminInitStandardPaperVO> chapterCode4JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode4,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode4JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode4JudgeList)) {
                allList.addAll(chapterCode4JudgeList);
            }
            int chapterCode4SingleLimit = 2;
            List<AdminInitStandardPaperVO> chapterCode4SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode4,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode4SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode4SingleList)) {
                allList.addAll(chapterCode4SingleList);
            }

            int chapterCode5 = 5;
            int chapterCode5JudgeLimit = 4;
            List<AdminInitStandardPaperVO> chapterCode5JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode5,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode5JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode5JudgeList)) {
                allList.addAll(chapterCode5JudgeList);
            }
            int chapterCode5SingleLimit = 6;
            List<AdminInitStandardPaperVO> chapterCode5SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode5,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode5SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode5SingleList)) {
                allList.addAll(chapterCode5SingleList);
            }
            //地方题抽取
            Integer regionJudgeLimit = 2;
            Integer regionSingleLimit = 3;
            List<AdminInitStandardPaperVO> regionJudgeList = iInitStandardPaperMapper.listRegionCarStandardPaper(subject, QuestionTypeEnum.JUDGE.getType(),
                    tenantRegionConfigDO.getQuestionSetId(), regionJudgeLimit);
            if (CollUtil.isNotEmpty(regionJudgeList)) {
                allList.addAll(regionJudgeList);
            }
            List<AdminInitStandardPaperVO> regionSingleList = iInitStandardPaperMapper.listRegionCarStandardPaper(subject, QuestionTypeEnum.SINGLE.getType(),
                    tenantRegionConfigDO.getQuestionSetId(), regionSingleLimit);
            if (CollUtil.isNotEmpty(regionSingleList)) {
                allList.addAll(regionSingleList);
            }
        } else {
            int chapterCode1 = 1;
            int chapterCode1JudgeLimit = 14;
            List<AdminInitStandardPaperVO> chapterCode1JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode1,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode1JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode1JudgeList)) {
                allList.addAll(chapterCode1JudgeList);
            }
            int chapterCode1SingleLimit = 21;
            List<AdminInitStandardPaperVO> chapterCode1SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode1,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode1SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode1SingleList)) {
                allList.addAll(chapterCode1SingleList);
            }

            int chapterCode2 = 2;
            int chapterCode2JudgeLimit = 17;
            List<AdminInitStandardPaperVO> chapterCode2JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode2,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode2JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode2JudgeList)) {
                allList.addAll(chapterCode2JudgeList);
            }
            int chapterCode2SingleLimit = 24;
            List<AdminInitStandardPaperVO> chapterCode2SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode2,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode2SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode2SingleList)) {
                allList.addAll(chapterCode2SingleList);
            }

            int chapterCode3 = 3;
            int chapterCode3JudgeLimit = 3;
            List<AdminInitStandardPaperVO> chapterCode3JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode3,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode3JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode3JudgeList)) {
                allList.addAll(chapterCode3JudgeList);
            }
            int chapterCode3SingleLimit = 6;
            List<AdminInitStandardPaperVO> chapterCode3SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode3,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode3SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode3SingleList)) {
                allList.addAll(chapterCode3SingleList);
            }

            int chapterCode4 = 4;
            int chapterCode4JudgeLimit = 2;
            List<AdminInitStandardPaperVO> chapterCode4JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode4,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode4JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode4JudgeList)) {
                allList.addAll(chapterCode4JudgeList);
            }
            int chapterCode4SingleLimit = 3;
            List<AdminInitStandardPaperVO> chapterCode4SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode4,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode4SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode4SingleList)) {
                allList.addAll(chapterCode4SingleList);
            }

            int chapterCode5 = 5;
            int chapterCode5JudgeLimit = 4;
            List<AdminInitStandardPaperVO> chapterCode5JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode5,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode5JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode5JudgeList)) {
                allList.addAll(chapterCode5JudgeList);
            }
            int chapterCode5SingleLimit = 6;
            List<AdminInitStandardPaperVO> chapterCode5SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode5,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode5SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode5SingleList)) {
                allList.addAll(chapterCode5SingleList);
            }
        }
        if (CollUtil.isNotEmpty(allList)) {
            List<StandardPaperDO> doList = new ArrayList<>();
            for (AdminInitStandardPaperVO vo : allList) {
                StandardPaperDO paperDO = new StandardPaperDO();
                paperDO.setSubject(vo.getSubject());
                paperDO.setBatchNum(batchNum);
                paperDO.setQuestionId(vo.getQuestionId());
                paperDO.setCarType(carType);
                doList.add(paperDO);
            }
            if (CollUtil.isNotEmpty(doList)) {
                standardPaperMapper.insertBatch(doList);
            }
        }
    }

    @Override
    public void initStandardPaperForMotoAndSubject1(Integer batchNum) {
        int carType = CarTypeEnum.MOTO.getType();
        int subject = SubjectEnum.ONE.getType();
        List<AdminInitStandardPaperVO> allList = new ArrayList<>();

        int chapterCode1 = 1;
        int chapterCode1JudgeLimit = 6;
        List<AdminInitStandardPaperVO> chapterCode1JudgeList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode1,
                        QuestionTypeEnum.JUDGE.getType(), chapterCode1JudgeLimit);
        if (CollUtil.isNotEmpty(chapterCode1JudgeList)) {
            allList.addAll(chapterCode1JudgeList);
        }
        int chapterCode1SingleLimit = 7;
        List<AdminInitStandardPaperVO> chapterCode1SingleList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode1,
                        QuestionTypeEnum.SINGLE.getType(), chapterCode1SingleLimit);
        if (CollUtil.isNotEmpty(chapterCode1SingleList)) {
            allList.addAll(chapterCode1SingleList);
        }

        int chapterCode2 = 2;
        int chapterCode2JudgeLimit = 10;
        List<AdminInitStandardPaperVO> chapterCode2JudgeList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode2,
                        QuestionTypeEnum.JUDGE.getType(), chapterCode2JudgeLimit);
        if (CollUtil.isNotEmpty(chapterCode2JudgeList)) {
            allList.addAll(chapterCode2JudgeList);
        }
        int chapterCode2SingleLimit = 21;
        List<AdminInitStandardPaperVO> chapterCode2SingleList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode2,
                        QuestionTypeEnum.SINGLE.getType(), chapterCode2SingleLimit);
        if (CollUtil.isNotEmpty(chapterCode2SingleList)) {
            allList.addAll(chapterCode2SingleList);
        }
        int chapterCode3 = 3;
        int chapterCode3JudgeLimit = 3;
        List<AdminInitStandardPaperVO> chapterCode3JudgeList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode3,
                        QuestionTypeEnum.JUDGE.getType(), chapterCode3JudgeLimit);
        if (CollUtil.isNotEmpty(chapterCode3JudgeList)) {
            allList.addAll(chapterCode3JudgeList);
        }
        int chapterCode3SingleLimit = 2;
        List<AdminInitStandardPaperVO> chapterCode3SingleList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode3,
                        QuestionTypeEnum.SINGLE.getType(), chapterCode3SingleLimit);
        if (CollUtil.isNotEmpty(chapterCode3SingleList)) {
            allList.addAll(chapterCode3SingleList);
        }
        int chapterCode4 = 4;
        int chapterCode4JudgeLimit = 1;
        List<AdminInitStandardPaperVO> chapterCode4JudgeList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode4,
                        QuestionTypeEnum.JUDGE.getType(), chapterCode4JudgeLimit);
        if (CollUtil.isNotEmpty(chapterCode4JudgeList)) {
            allList.addAll(chapterCode4JudgeList);
        }
        if (CollUtil.isNotEmpty(allList)) {
            List<StandardPaperDO> doList = new ArrayList<>();
            for (AdminInitStandardPaperVO vo : allList) {
                StandardPaperDO paperDO = new StandardPaperDO();
                paperDO.setSubject(vo.getSubject());
                paperDO.setBatchNum(batchNum);
                paperDO.setQuestionId(vo.getQuestionId());
                paperDO.setCarType(carType);
                doList.add(paperDO);
            }
            if (CollUtil.isNotEmpty(doList)) {
                standardPaperMapper.insertBatch(doList);
            }
        }
    }

    @Override
    public void initPersonalPaperForMotoAndSubject1(Long memberId) {
        int carType = CarTypeEnum.MOTO.getType();
        int subject = SubjectEnum.ONE.getType();
        List<AdminInitPersonalPaperVO> allList = new ArrayList<>();

        int judgeLimit = 20;
        List<AdminInitPersonalPaperVO> judgeList =
                iInitPersonalPaperMapper.listInitMoToPersonalPaper(memberId, carType, subject,
                        QuestionTypeEnum.JUDGE.getType(), judgeLimit);
        if (CollUtil.isNotEmpty(judgeList)) {
            allList.addAll(judgeList);
        }

        int singleLimit = 20;
        List<AdminInitPersonalPaperVO> singleList =
                iInitPersonalPaperMapper.listInitMoToPersonalPaper(memberId, carType, subject,
                        QuestionTypeEnum.SINGLE.getType(), singleLimit);
        if (CollUtil.isNotEmpty(singleList)) {
            allList.addAll(singleList);
        }
        if (CollUtil.isNotEmpty(allList)) {
            List<PersonalPaperDO> doList = new ArrayList<>();
            for (AdminInitPersonalPaperVO vo : allList) {
                PersonalPaperDO paperDO = new PersonalPaperDO();
                paperDO.setCarType(carType);
                paperDO.setSubject(vo.getSubject());
                paperDO.setQuestionId(vo.getQuestionId());
                paperDO.setMemberId(memberId);
                paperDO.setCarType(carType);
                doList.add(paperDO);
            }
            if (CollUtil.isNotEmpty(doList)) {
                personalPaperMapper.insertBatch(doList);
            }
        }
    }

    @Override
    public void initStandardPaperForCarAndSubject4(Integer batchNum) {
        int carType = CarTypeEnum.CAR.getType();
        int subject = SubjectEnum.FOUR.getType();
        List<AdminInitStandardPaperVO> allList = new ArrayList<>();

        //先判断是否有地方题
        TenantRegionConfigDO tenantRegionConfigDO = tenantRegionConfigMapper.selectOne(new LambdaQueryWrapperX<TenantRegionConfigDO>()
                .eq(TenantRegionConfigDO::getSubject, subject));
        if (ObjectUtil.isNotNull(tenantRegionConfigDO)) {
            int chapterCode1 = 1;
            int chapterCode1JudgeLimit = 4;
            List<AdminInitStandardPaperVO> chapterCode1JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode1,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode1JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode1JudgeList)) {
                allList.addAll(chapterCode1JudgeList);
            }

            int chapterCode1SingleLimit = 4;
            List<AdminInitStandardPaperVO> chapterCode1SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode1,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode1SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode1SingleList)) {
                allList.addAll(chapterCode1SingleList);
            }

            int chapterCode1MultipleLimit = 2;
            List<AdminInitStandardPaperVO> chapterCode1MultipleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode1,
                            QuestionTypeEnum.MULTIPLE.getType(), chapterCode1MultipleLimit);
            if (CollUtil.isNotEmpty(chapterCode1MultipleList)) {
                allList.addAll(chapterCode1MultipleList);
            }
            int chapterCode2 = 2;
            int chapterCode2JudgeLimit = 2;
            List<AdminInitStandardPaperVO> chapterCode2JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode2,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode2JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode2JudgeList)) {
                allList.addAll(chapterCode2JudgeList);
            }

            int chapterCode2SingleLimit = 4;
            List<AdminInitStandardPaperVO> chapterCode2SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode2,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode2SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode2SingleList)) {
                allList.addAll(chapterCode2SingleList);
            }

            int chapterCode2MultipleLimit = 2;
            List<AdminInitStandardPaperVO> chapterCode2MultipleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode2,
                            QuestionTypeEnum.MULTIPLE.getType(), chapterCode2MultipleLimit);
            if (CollUtil.isNotEmpty(chapterCode2MultipleList)) {
                allList.addAll(chapterCode2MultipleList);
            }
            int chapterCode3 = 3;
            int chapterCode3JudgeLimit = 5;
            List<AdminInitStandardPaperVO> chapterCode3JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode3,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode3JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode3JudgeList)) {
                allList.addAll(chapterCode3JudgeList);
            }

            int chapterCode3SingleLimit = 2;
            List<AdminInitStandardPaperVO> chapterCode3SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode3,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode3SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode3SingleList)) {
                allList.addAll(chapterCode3SingleList);
            }

            int chapterCode3MultipleLimit = 1;
            List<AdminInitStandardPaperVO> chapterCode3MultipleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode3,
                            QuestionTypeEnum.MULTIPLE.getType(), chapterCode3MultipleLimit);
            if (CollUtil.isNotEmpty(chapterCode3MultipleList)) {
                allList.addAll(chapterCode3MultipleList);
            }
            int chapterCode4 = 4;
            int chapterCode4JudgeLimit = 4;
            List<AdminInitStandardPaperVO> chapterCode4JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode4,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode4JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode4JudgeList)) {
                allList.addAll(chapterCode4JudgeList);
            }

            int chapterCode4SingleLimit = 5;
            List<AdminInitStandardPaperVO> chapterCode4SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode4,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode4SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode4SingleList)) {
                allList.addAll(chapterCode4SingleList);
            }

            int chapterCode4MultipleLimit = 2;
            List<AdminInitStandardPaperVO> chapterCode4MultipleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode4,
                            QuestionTypeEnum.MULTIPLE.getType(), chapterCode4MultipleLimit);
            if (CollUtil.isNotEmpty(chapterCode4MultipleList)) {
                allList.addAll(chapterCode4MultipleList);
            }
            int chapterCode5 = 5;
            int chapterCode5JudgeLimit = 3;
            List<AdminInitStandardPaperVO> chapterCode5JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode5,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode5JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode5JudgeList)) {
                allList.addAll(chapterCode5JudgeList);
            }

            int chapterCode5SingleLimit = 2;
            List<AdminInitStandardPaperVO> chapterCode5SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode5,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode5SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode5SingleList)) {
                allList.addAll(chapterCode5SingleList);
            }

            int chapterCode5MultipleLimit = 1;
            List<AdminInitStandardPaperVO> chapterCode5MultipleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode5,
                            QuestionTypeEnum.MULTIPLE.getType(), chapterCode5MultipleLimit);
            if (CollUtil.isNotEmpty(chapterCode5MultipleList)) {
                allList.addAll(chapterCode5MultipleList);
            }
            int chapterCode6 = 6;
            int chapterCode6JudgeLimit = 1;
            List<AdminInitStandardPaperVO> chapterCode6JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode6,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode6JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode6JudgeList)) {
                allList.addAll(chapterCode6JudgeList);
            }

            int chapterCode6SingleLimit = 1;
            List<AdminInitStandardPaperVO> chapterCode6SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode6,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode6SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode6SingleList)) {
                allList.addAll(chapterCode6SingleList);
            }

            int chapterCode6MultipleLimit = 1;
            List<AdminInitStandardPaperVO> chapterCode6MultipleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode6,
                            QuestionTypeEnum.MULTIPLE.getType(), chapterCode6MultipleLimit);
            if (CollUtil.isNotEmpty(chapterCode6MultipleList)) {
                allList.addAll(chapterCode6MultipleList);
            }
            int chapterCode7 = 7;
            int chapterCode7SingleLimit = 1;
            List<AdminInitStandardPaperVO> chapterCode7SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode7,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode7SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode7SingleList)) {
                allList.addAll(chapterCode7SingleList);
            }

            int chapterCode7MultipleLimit = 1;
            List<AdminInitStandardPaperVO> chapterCode7MultipleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode7,
                            QuestionTypeEnum.MULTIPLE.getType(), chapterCode7MultipleLimit);
            if (CollUtil.isNotEmpty(chapterCode7MultipleList)) {
                allList.addAll(chapterCode7MultipleList);
            }
            //地方题
            Integer regionJudgeLimit = 1;
            Integer regionSingleLimit = 1;
            List<AdminInitStandardPaperVO> regionJudgeList = iInitStandardPaperMapper.listRegionCarStandardPaper(subject,
                    QuestionTypeEnum.JUDGE.getType(),
                    tenantRegionConfigDO.getQuestionSetId(), regionJudgeLimit);
            if (CollUtil.isNotEmpty(regionJudgeList)) {
                allList.addAll(regionJudgeList);
            }
            List<AdminInitStandardPaperVO> regionSingleList = iInitStandardPaperMapper.listRegionCarStandardPaper(subject,
                    QuestionTypeEnum.SINGLE.getType(),
                    tenantRegionConfigDO.getQuestionSetId(), regionSingleLimit);
            if (CollUtil.isNotEmpty(regionSingleList)) {
                allList.addAll(regionSingleList);
            }
        } else {
            int chapterCode1 = 1;
            int chapterCode1JudgeLimit = 4;
            List<AdminInitStandardPaperVO> chapterCode1JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode1,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode1JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode1JudgeList)) {
                allList.addAll(chapterCode1JudgeList);
            }

            int chapterCode1SingleLimit = 4;
            List<AdminInitStandardPaperVO> chapterCode1SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode1,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode1SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode1SingleList)) {
                allList.addAll(chapterCode1SingleList);
            }

            int chapterCode1MultipleLimit = 2;
            List<AdminInitStandardPaperVO> chapterCode1MultipleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode1,
                            QuestionTypeEnum.MULTIPLE.getType(), chapterCode1MultipleLimit);
            if (CollUtil.isNotEmpty(chapterCode1MultipleList)) {
                allList.addAll(chapterCode1MultipleList);
            }
            int chapterCode2 = 2;
            int chapterCode2JudgeLimit = 2;
            List<AdminInitStandardPaperVO> chapterCode2JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode2,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode2JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode2JudgeList)) {
                allList.addAll(chapterCode2JudgeList);
            }

            int chapterCode2SingleLimit = 4;
            List<AdminInitStandardPaperVO> chapterCode2SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode2,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode2SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode2SingleList)) {
                allList.addAll(chapterCode2SingleList);
            }

            int chapterCode2MultipleLimit = 2;
            List<AdminInitStandardPaperVO> chapterCode2MultipleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode2,
                            QuestionTypeEnum.MULTIPLE.getType(), chapterCode2MultipleLimit);
            if (CollUtil.isNotEmpty(chapterCode2MultipleList)) {
                allList.addAll(chapterCode2MultipleList);
            }
            int chapterCode3 = 3;
            int chapterCode3JudgeLimit = 6;
            List<AdminInitStandardPaperVO> chapterCode3JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode3,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode3JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode3JudgeList)) {
                allList.addAll(chapterCode3JudgeList);
            }

            int chapterCode3SingleLimit = 2;
            List<AdminInitStandardPaperVO> chapterCode3SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode3,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode3SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode3SingleList)) {
                allList.addAll(chapterCode3SingleList);
            }

            int chapterCode3MultipleLimit = 1;
            List<AdminInitStandardPaperVO> chapterCode3MultipleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode3,
                            QuestionTypeEnum.MULTIPLE.getType(), chapterCode3MultipleLimit);
            if (CollUtil.isNotEmpty(chapterCode3MultipleList)) {
                allList.addAll(chapterCode3MultipleList);
            }
            int chapterCode4 = 4;
            int chapterCode4JudgeLimit = 4;
            List<AdminInitStandardPaperVO> chapterCode4JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode4,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode4JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode4JudgeList)) {
                allList.addAll(chapterCode4JudgeList);
            }

            int chapterCode4SingleLimit = 6;
            List<AdminInitStandardPaperVO> chapterCode4SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode4,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode4SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode4SingleList)) {
                allList.addAll(chapterCode4SingleList);
            }

            int chapterCode4MultipleLimit = 2;
            List<AdminInitStandardPaperVO> chapterCode4MultipleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode4,
                            QuestionTypeEnum.MULTIPLE.getType(), chapterCode4MultipleLimit);
            if (CollUtil.isNotEmpty(chapterCode4MultipleList)) {
                allList.addAll(chapterCode4MultipleList);
            }
            int chapterCode5 = 5;
            int chapterCode5JudgeLimit = 3;
            List<AdminInitStandardPaperVO> chapterCode5JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode5,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode5JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode5JudgeList)) {
                allList.addAll(chapterCode5JudgeList);
            }

            int chapterCode5SingleLimit = 2;
            List<AdminInitStandardPaperVO> chapterCode5SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode5,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode5SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode5SingleList)) {
                allList.addAll(chapterCode5SingleList);
            }

            int chapterCode5MultipleLimit = 1;
            List<AdminInitStandardPaperVO> chapterCode5MultipleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode5,
                            QuestionTypeEnum.MULTIPLE.getType(), chapterCode5MultipleLimit);
            if (CollUtil.isNotEmpty(chapterCode5MultipleList)) {
                allList.addAll(chapterCode5MultipleList);
            }
            int chapterCode6 = 6;
            int chapterCode6JudgeLimit = 1;
            List<AdminInitStandardPaperVO> chapterCode6JudgeList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode6,
                            QuestionTypeEnum.JUDGE.getType(), chapterCode6JudgeLimit);
            if (CollUtil.isNotEmpty(chapterCode6JudgeList)) {
                allList.addAll(chapterCode6JudgeList);
            }

            int chapterCode6SingleLimit = 1;
            List<AdminInitStandardPaperVO> chapterCode6SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode6,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode6SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode6SingleList)) {
                allList.addAll(chapterCode6SingleList);
            }

            int chapterCode6MultipleLimit = 1;
            List<AdminInitStandardPaperVO> chapterCode6MultipleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode6,
                            QuestionTypeEnum.MULTIPLE.getType(), chapterCode6MultipleLimit);
            if (CollUtil.isNotEmpty(chapterCode6MultipleList)) {
                allList.addAll(chapterCode6MultipleList);
            }
            int chapterCode7 = 7;
            int chapterCode7SingleLimit = 1;
            List<AdminInitStandardPaperVO> chapterCode7SingleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode7,
                            QuestionTypeEnum.SINGLE.getType(), chapterCode7SingleLimit);
            if (CollUtil.isNotEmpty(chapterCode7SingleList)) {
                allList.addAll(chapterCode7SingleList);
            }

            int chapterCode7MultipleLimit = 1;
            List<AdminInitStandardPaperVO> chapterCode7MultipleList =
                    iInitStandardPaperMapper.listInitCarStandardPaper(carType, subject, chapterCode7,
                            QuestionTypeEnum.MULTIPLE.getType(), chapterCode7MultipleLimit);
            if (CollUtil.isNotEmpty(chapterCode7MultipleList)) {
                allList.addAll(chapterCode7MultipleList);
            }
        }
        if (CollUtil.isNotEmpty(allList)) {
            List<StandardPaperDO> doList = new ArrayList<>();
            for (AdminInitStandardPaperVO vo : allList) {
                StandardPaperDO paperDO = new StandardPaperDO();
                paperDO.setSubject(vo.getSubject());
                paperDO.setBatchNum(batchNum);
                paperDO.setQuestionId(vo.getQuestionId());
                paperDO.setCarType(carType);
                doList.add(paperDO);
            }
            if (CollUtil.isNotEmpty(doList)) {
                standardPaperMapper.insertBatch(doList);
            }
        }
    }

    @Override
    public void initPersonalPaperForCarAndSubject4(Long memberId) {
        int carType = CarTypeEnum.CAR.getType();
        int subject = SubjectEnum.FOUR.getType();
        List<AdminInitPersonalPaperVO> allList = new ArrayList<>();

        int chapterCode2 = 2;
        int chapterCode2Limit = 9;
        List<AdminInitPersonalPaperVO> chapterCode2List =
                iInitPersonalPaperMapper.listInitCarPersonalPaper(memberId, carType, subject,
                        chapterCode2, QuestionTypeEnum.JUDGE.getType(), chapterCode2Limit);
        if (CollUtil.isNotEmpty(chapterCode2List)) {
            allList.addAll(chapterCode2List);
        }

        int chapterCode4 = 4;
        int chapterCode4Limit = 8;
        List<AdminInitPersonalPaperVO> chapterCode4List =
                iInitPersonalPaperMapper.listInitCarPersonalPaper(memberId, carType, subject,
                        chapterCode4, QuestionTypeEnum.JUDGE.getType(), chapterCode4Limit);
        if (CollUtil.isNotEmpty(chapterCode4List)) {
            allList.addAll(chapterCode4List);
        }

        int chapterCode7 = 7;
        int chapterCode7Limit = 3;
        List<AdminInitPersonalPaperVO> chapterCode7List =
                iInitPersonalPaperMapper.listInitCarPersonalPaper(memberId, carType, subject,
                        chapterCode7, QuestionTypeEnum.JUDGE.getType(), chapterCode7Limit);
        if (CollUtil.isNotEmpty(chapterCode7List)) {
            allList.addAll(chapterCode7List);
        }

        int chapterCode3 = 3;
        int chapterCode3Limit = 3;
        List<AdminInitPersonalPaperVO> chapterCode3List =
                iInitPersonalPaperMapper.listInitCarPersonalPaper(memberId, carType, subject,
                        chapterCode3, QuestionTypeEnum.SINGLE.getType(), chapterCode3Limit);
        if (CollUtil.isNotEmpty(chapterCode3List)) {
            allList.addAll(chapterCode3List);
        }

        int chapterCode5 = 5;
        int chapterCode5Limit = 5;
        List<AdminInitPersonalPaperVO> chapterCode5List =
                iInitPersonalPaperMapper.listInitCarPersonalPaper(memberId, carType, subject,
                        chapterCode5, QuestionTypeEnum.SINGLE.getType(), chapterCode5Limit);
        if (CollUtil.isNotEmpty(chapterCode5List)) {
            allList.addAll(chapterCode5List);
        }

        int chapterCode6 = 6;
        int chapterCode6Limit = 6;
        List<AdminInitPersonalPaperVO> chapterCode6List =
                iInitPersonalPaperMapper.listInitCarPersonalPaper(memberId, carType, subject,
                        chapterCode6, QuestionTypeEnum.SINGLE.getType(), chapterCode6Limit);
        if (CollUtil.isNotEmpty(chapterCode6List)) {
            allList.addAll(chapterCode6List);
        }
        if (CollUtil.isNotEmpty(allList)) {
            List<PersonalPaperDO> doList = new ArrayList<>();
            for (AdminInitPersonalPaperVO vo : allList) {
                PersonalPaperDO paperDO = new PersonalPaperDO();
                paperDO.setCarType(carType);
                paperDO.setSubject(vo.getSubject());
                paperDO.setQuestionId(vo.getQuestionId());
                paperDO.setMemberId(memberId);
                paperDO.setCarType(carType);
                doList.add(paperDO);
            }
            if (CollUtil.isNotEmpty(doList)) {
                personalPaperMapper.insertBatch(doList);
            }
        }
    }

    @Override
    public void initStandardPaperForMotoAndSubject4(Integer batchNum) {
        int carType = CarTypeEnum.MOTO.getType();
        int subject = SubjectEnum.FOUR.getType();
        List<AdminInitStandardPaperVO> allList = new ArrayList<>();

        int chapterCode1 = 1;
        int chapterCode1JudgeLimit = 4;
        List<AdminInitStandardPaperVO> chapterCode1JudgeList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode1,
                        QuestionTypeEnum.JUDGE.getType(), chapterCode1JudgeLimit);
        if (CollUtil.isNotEmpty(chapterCode1JudgeList)) {
            allList.addAll(chapterCode1JudgeList);
        }

        int chapterCode1SingleLimit = 2;
        List<AdminInitStandardPaperVO> chapterCode1SingleList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode1,
                        QuestionTypeEnum.SINGLE.getType(), chapterCode1SingleLimit);
        if (CollUtil.isNotEmpty(chapterCode1SingleList)) {
            allList.addAll(chapterCode1SingleList);
        }

        int chapterCode1MultipleLimit = 3;
        List<AdminInitStandardPaperVO> chapterCode1MultipleList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode1,
                        QuestionTypeEnum.MULTIPLE.getType(), chapterCode1MultipleLimit);
        if (CollUtil.isNotEmpty(chapterCode1MultipleList)) {
            allList.addAll(chapterCode1MultipleList);
        }
        int chapterCode2 = 2;
        int chapterCode2JudgeLimit = 3;
        List<AdminInitStandardPaperVO> chapterCode2JudgeList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode2,
                        QuestionTypeEnum.JUDGE.getType(), chapterCode2JudgeLimit);
        if (CollUtil.isNotEmpty(chapterCode2JudgeList)) {
            allList.addAll(chapterCode2JudgeList);
        }

        int chapterCode2SingleLimit = 3;
        List<AdminInitStandardPaperVO> chapterCode2SingleList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode2,
                        QuestionTypeEnum.SINGLE.getType(), chapterCode2SingleLimit);
        if (CollUtil.isNotEmpty(chapterCode2SingleList)) {
            allList.addAll(chapterCode2SingleList);
        }

        int chapterCode2MultipleLimit = 1;
        List<AdminInitStandardPaperVO> chapterCode2MultipleList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode2,
                        QuestionTypeEnum.MULTIPLE.getType(), chapterCode2MultipleLimit);
        if (CollUtil.isNotEmpty(chapterCode2MultipleList)) {
            allList.addAll(chapterCode2MultipleList);
        }
        int chapterCode3 = 3;
        int chapterCode3JudgeLimit = 1;
        List<AdminInitStandardPaperVO> chapterCode3JudgeList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode3,
                        QuestionTypeEnum.JUDGE.getType(), chapterCode3JudgeLimit);
        if (CollUtil.isNotEmpty(chapterCode3JudgeList)) {
            allList.addAll(chapterCode3JudgeList);
        }

        int chapterCode3SingleLimit = 7;
        List<AdminInitStandardPaperVO> chapterCode3SingleList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode3,
                        QuestionTypeEnum.SINGLE.getType(), chapterCode3SingleLimit);
        if (CollUtil.isNotEmpty(chapterCode3SingleList)) {
            allList.addAll(chapterCode3SingleList);
        }

        int chapterCode4 = 4;
        int chapterCode4JudgeLimit = 4;
        List<AdminInitStandardPaperVO> chapterCode4JudgeList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode4,
                        QuestionTypeEnum.JUDGE.getType(), chapterCode4JudgeLimit);
        if (CollUtil.isNotEmpty(chapterCode4JudgeList)) {
            allList.addAll(chapterCode4JudgeList);
        }

        int chapterCode4SingleLimit = 3;
        List<AdminInitStandardPaperVO> chapterCode4SingleList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode4,
                        QuestionTypeEnum.SINGLE.getType(), chapterCode4SingleLimit);
        if (CollUtil.isNotEmpty(chapterCode4SingleList)) {
            allList.addAll(chapterCode4SingleList);
        }

        int chapterCode4MultipleLimit = 3;
        List<AdminInitStandardPaperVO> chapterCode4MultipleList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode4,
                        QuestionTypeEnum.MULTIPLE.getType(), chapterCode4MultipleLimit);
        if (CollUtil.isNotEmpty(chapterCode4MultipleList)) {
            allList.addAll(chapterCode4MultipleList);
        }

        int chapterCode5 = 5;
        int chapterCode5JudgeLimit = 3;
        List<AdminInitStandardPaperVO> chapterCode5JudgeList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode5,
                        QuestionTypeEnum.JUDGE.getType(), chapterCode5JudgeLimit);
        if (CollUtil.isNotEmpty(chapterCode5JudgeList)) {
            allList.addAll(chapterCode5JudgeList);
        }

        int chapterCode5SingleLimit = 1;
        List<AdminInitStandardPaperVO> chapterCode5SingleList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode5,
                        QuestionTypeEnum.SINGLE.getType(), chapterCode5SingleLimit);
        if (CollUtil.isNotEmpty(chapterCode5SingleList)) {
            allList.addAll(chapterCode5SingleList);
        }

        int chapterCode5MultipleLimit = 1;
        List<AdminInitStandardPaperVO> chapterCode5MultipleList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode5,
                        QuestionTypeEnum.MULTIPLE.getType(), chapterCode5MultipleLimit);
        if (CollUtil.isNotEmpty(chapterCode5MultipleList)) {
            allList.addAll(chapterCode5MultipleList);
        }

        int chapterCode6 = 6;
        int chapterCode6JudgeLimit = 4;
        List<AdminInitStandardPaperVO> chapterCode6JudgeList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode6,
                        QuestionTypeEnum.JUDGE.getType(), chapterCode6JudgeLimit);
        if (CollUtil.isNotEmpty(chapterCode6JudgeList)) {
            allList.addAll(chapterCode6JudgeList);
        }

        int chapterCode6SingleLimit = 3;
        List<AdminInitStandardPaperVO> chapterCode6SingleList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode6,
                        QuestionTypeEnum.SINGLE.getType(), chapterCode6SingleLimit);
        if (CollUtil.isNotEmpty(chapterCode6SingleList)) {
            allList.addAll(chapterCode6SingleList);
        }

        int chapterCode6MultipleLimit = 1;
        List<AdminInitStandardPaperVO> chapterCode6MultipleList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode6,
                        QuestionTypeEnum.MULTIPLE.getType(), chapterCode6MultipleLimit);
        if (CollUtil.isNotEmpty(chapterCode6MultipleList)) {
            allList.addAll(chapterCode6MultipleList);
        }

        int chapterCode7 = 7;
        int chapterCode7JudgeLimit = 1;
        List<AdminInitStandardPaperVO> chapterCode7JudgeList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode7,
                        QuestionTypeEnum.JUDGE.getType(), chapterCode7JudgeLimit);
        if (CollUtil.isNotEmpty(chapterCode7JudgeList)) {
            allList.addAll(chapterCode7JudgeList);
        }

        int chapterCode7SingleLimit = 1;
        List<AdminInitStandardPaperVO> chapterCode7SingleList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode7,
                        QuestionTypeEnum.SINGLE.getType(), chapterCode7SingleLimit);
        if (CollUtil.isNotEmpty(chapterCode7SingleList)) {
            allList.addAll(chapterCode7SingleList);
        }

        int chapterCode7MultipleLimit = 1;
        List<AdminInitStandardPaperVO> chapterCode7MultipleList =
                iInitStandardPaperMapper.listInitMoToStandardPaper(carType, subject, chapterCode7,
                        QuestionTypeEnum.MULTIPLE.getType(), chapterCode7MultipleLimit);
        if (CollUtil.isNotEmpty(chapterCode7MultipleList)) {
            allList.addAll(chapterCode7MultipleList);
        }

        if (CollUtil.isNotEmpty(allList)) {
            List<StandardPaperDO> doList = new ArrayList<>();
            for (AdminInitStandardPaperVO vo : allList) {
                StandardPaperDO paperDO = new StandardPaperDO();
                paperDO.setSubject(vo.getSubject());
                paperDO.setBatchNum(batchNum);
                paperDO.setQuestionId(vo.getQuestionId());
                paperDO.setCarType(carType);
                doList.add(paperDO);
            }
            if (CollUtil.isNotEmpty(doList)) {
                standardPaperMapper.insertBatch(doList);
            }
        }
    }

    @Override
    public void initPersonalPaperForMotoAndSubject4(Long memberId) {
        int carType = CarTypeEnum.MOTO.getType();
        int subject = SubjectEnum.FOUR.getType();
        List<AdminInitPersonalPaperVO> allList = new ArrayList<>();

        int judgeLimit = 20;
        List<AdminInitPersonalPaperVO> judgeList =
                iInitPersonalPaperMapper.listInitMoToPersonalPaper(memberId, carType, subject,
                        QuestionTypeEnum.JUDGE.getType(), judgeLimit);
        if (CollUtil.isNotEmpty(judgeList)) {
            allList.addAll(judgeList);
        }

        int singleLimit = 20;
        List<AdminInitPersonalPaperVO> singleList =
                iInitPersonalPaperMapper.listInitMoToPersonalPaper(memberId, carType, subject,
                        QuestionTypeEnum.SINGLE.getType(), singleLimit);
        if (CollUtil.isNotEmpty(singleList)) {
            allList.addAll(singleList);
        }

        int multipleLimit = 10;
        List<AdminInitPersonalPaperVO> multipleList =
                iInitPersonalPaperMapper.listInitMoToPersonalPaper(memberId, carType, subject,
                        QuestionTypeEnum.MULTIPLE.getType(), multipleLimit);
        if (CollUtil.isNotEmpty(multipleList)) {
            allList.addAll(multipleList);
        }

        if (CollUtil.isNotEmpty(allList)) {
            List<PersonalPaperDO> doList = new ArrayList<>();
            for (AdminInitPersonalPaperVO vo : allList) {
                PersonalPaperDO paperDO = new PersonalPaperDO();
                paperDO.setCarType(carType);
                paperDO.setSubject(vo.getSubject());
                paperDO.setQuestionId(vo.getQuestionId());
                paperDO.setMemberId(memberId);
                paperDO.setCarType(carType);
                doList.add(paperDO);
            }
            if (CollUtil.isNotEmpty(doList)) {
                personalPaperMapper.insertBatch(doList);
            }
        }
    }

    @Override
    @TenantIgnore
    public PageResult<AppQuestionPageRespVO> getQuestionBySetIdPage(AppQuestionSetPageReqVO reqVO) {
        Page<AppQuestionSetPageReqVO> page = new Page<>(reqVO.getPageNo(), reqVO.getPageSize());
        IPage<AppQuestionPageRespVO> questionBySetIdPage = questionMapper.getQuestionBySetIdPage(page, reqVO);
        return new PageResult<>(questionBySetIdPage.getRecords(), questionBySetIdPage.getTotal());
    }

    @Override
    @TenantIgnore
    public List<Long> getQuestionIdListBySetId(Long questionSetId) {
        return questionMapper.getQuestionIdListBySetId(questionSetId);
    }

    @Override
    public PageResult<AppQuestionPageRespVO> getQuestionByTagIdPage(AppQuestionTagPageReqVO reqVO) {
        Page<AppQuestionTagPageReqVO> page = new Page<>(reqVO.getPageNo(), reqVO.getPageSize());
        IPage<AppQuestionPageRespVO> questionByTagIdPage = questionMapper.getQuestionByTagIdPage(page, reqVO);
        return new PageResult<>(questionByTagIdPage.getRecords(), questionByTagIdPage.getTotal());
    }

    @Override
    @TenantIgnore
    public List<Long> getQuestionIdListByTagId(Long questionTagId) {
        return questionMapper.getQuestionIdListByTagId(questionTagId);
    }

    @Override
    @TenantIgnore
    public List<AppQuestionListRespVO> getQuestionListByIds(List<Long> ids) {
        if (CollUtil.isEmpty(ids)) {
            throw new ServiceException(GlobalErrorCodeConstants.BAD_REQUEST.getCode(), "参数错误");
        }
        return questionMapper.getQuestionListByIds(ids);
    }

    @Override
    public Boolean batchCreateMemberActionRecord(List<AppQuestionActionRecordReqVO> reqVOList) {
        if (CollUtil.isEmpty(reqVOList)) {
            throw new ServiceException(GlobalErrorCodeConstants.BAD_REQUEST.getCode(), "参数错误");
        }
        Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
        List<MemberQuestionRecordDO> updateMemberQuestionRecordList = new ArrayList<>();
        List<MemberQuestionRecordDO> addMemberQuestionRecordList = new ArrayList<>();
        for (AppQuestionActionRecordReqVO recordReqVO : reqVOList) {
            MemberQuestionRecordDO memberQuestionRecordDO = memberQuestionRecordMapper
                    .selectOne(new LambdaQueryWrapper<MemberQuestionRecordDO>()
                            .eq(MemberQuestionRecordDO::getQuestionId, recordReqVO.getQuestionId())
                            .eq(MemberQuestionRecordDO::getMemberId, loginUserId));
            if (ObjectUtil.isNotNull(memberQuestionRecordDO)) {
                //更新
                MemberQuestionRecordDO updateItem = QuestionConvert.INSTANCE.convertMemberQuestionRecordDO(recordReqVO);
                updateItem.setId(memberQuestionRecordDO.getId());
                updateMemberQuestionRecordList.add(updateItem);
            } else {
                //新增
                MemberQuestionRecordDO updateItem = QuestionConvert.INSTANCE.convertMemberQuestionRecordDO(recordReqVO);
                updateItem.setMemberId(loginUserId);
                addMemberQuestionRecordList.add(updateItem);
            }
        }
        if (CollUtil.isNotEmpty(updateMemberQuestionRecordList)) {
            memberQuestionRecordMapper.updateBatch(updateMemberQuestionRecordList
                    , updateMemberQuestionRecordList.size());
        }
        if (CollUtil.isNotEmpty(addMemberQuestionRecordList)) {
            memberQuestionRecordMapper.insertBatch(addMemberQuestionRecordList);
        }

        return Boolean.TRUE;
    }

    @Override
    public List<AppQuestionActionRecordReqVO> getMemberActionRecord(AppMemberActionRecordReqVO reqVO) {
        Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
        List<MemberQuestionRecordDO> recordDOList = memberQuestionRecordMapper
                .selectList(new LambdaQueryWrapperX<MemberQuestionRecordDO>()
                        .eqIfPresent(MemberQuestionRecordDO::getSourceFromType, reqVO.getSourceFromType())
                        .eqIfPresent(MemberQuestionRecordDO::getSourceFromId, reqVO.getSourceFromId())
                        .eq(MemberQuestionRecordDO::getMemberId, loginUserId));
        return QuestionConvert.INSTANCE.convertAppQuestionActionRecordList(recordDOList);
    }


    @Override
    public boolean createMemberPaperRecord(AppMemberPaperRecordReqVO reqVO) {
        MemberPaperRecordDO memberPaperRecordDO = QuestionConvert.INSTANCE.convertMemberPaperRecord(reqVO);
        memberPaperRecordDO.setMemberId(SecurityFrameworkUtils.getLoginUserId());
        memberPaperRecordMapper.insert(memberPaperRecordDO);
        return true;
    }

    @Override
    public AppMemberPaperRecordRespVO getPaperRecordByPaperId(Long paperId) {
        MemberPaperRecordDO memberPaperRecordDO = memberPaperRecordMapper.selectOne(new LambdaQueryWrapper<MemberPaperRecordDO>()
                .eq(MemberPaperRecordDO::getPaperId, paperId));
        return QuestionConvert.INSTANCE.convert(memberPaperRecordDO);
    }

    @Override
    public List<Long> getCurrentMemberErrorQuestionIdList(AppMemberErrorIdsReqVO reqVO) {
        return memberQuestionRecordMapper.getCurrentMemberErrorQuestionIdList(reqVO);
    }

    @Override
    public List<Long> getCurrentMemberCollectQuestionIdList(AppMemberCollectIdsReqVO reqVO) {
        return memberQuestionRecordMapper.getCurrentMemberCollectQuestionIdList(reqVO);
    }

    @Override
    public List<AppQuestionChapterListRespVO> getChapterListByIds(List<Long> ids) {
        List<QuestionChapterDO> questionChapterDOS = chapterMapper.selectList(new LambdaQueryWrapper<QuestionChapterDO>()
                .in(QuestionChapterDO::getId, ids));
        return QuestionConvert.INSTANCE.convert(questionChapterDOS);
    }

    @Override
    public List<AppQuestionChapterListRespVO> getChapterListByQuestionIds(List<Long> ids) {
        return questionMapper.selectJoinList(AppQuestionChapterListRespVO.class, new MPJLambdaWrapper<QuestionDO>()
                .in(QuestionDO::getId, ids)
                .leftJoin(QuestionChapterDO.class, QuestionChapterDO::getId, QuestionDO::getChapterId)
                .selectAll(QuestionChapterDO.class)
                .groupBy(QuestionChapterDO::getId)
                .selectCount(QuestionDO::getId, AppQuestionChapterListRespVO::getQuestionCount));
    }

    @Override
    public AppMemberPaperSummaryRespVO getMemberPaperSummary(AppMemberPaperSummaryReqVO reqVO) {
        AppMemberPaperSummaryRespVO respVO = new AppMemberPaperSummaryRespVO();
        Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
        Long examCount = memberPaperRecordMapper.selectCount(new LambdaQueryWrapper<MemberPaperRecordDO>()
                .eq(MemberPaperRecordDO::getMemberId, loginUserId)
                .eq(MemberPaperRecordDO::getSubject, reqVO.getSubject())
                .eq(MemberPaperRecordDO::getCarType, reqVO.getCarType()));
        Long passesCount = memberPaperRecordMapper.selectCount(new LambdaQueryWrapper<MemberPaperRecordDO>()
                .eq(MemberPaperRecordDO::getMemberId, loginUserId)
                .eq(MemberPaperRecordDO::getSubject, reqVO.getSubject())
                .eq(MemberPaperRecordDO::getCarType, reqVO.getCarType())
                .eq(MemberPaperRecordDO::getPassed, Boolean.TRUE));
        respVO.setExamCount(examCount);
        respVO.setPassesCount(passesCount);
        return respVO;
    }

    @Override
    public PageResult<AppMemberPaperRecordPageRespVO> getMemberPaperRecordPage(AppMemberPaperRecordPageReqVO reqVO) {
        Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
        Page<AppMemberPaperRecordPageReqVO> page = new Page<>(reqVO.getPageNo(), reqVO.getPageSize());
        IPage<AppMemberPaperRecordPageRespVO> memberPaperRecordPage
                = questionMapper.getMemberPaperRecordPage(page, reqVO, loginUserId);
        return new PageResult<>(memberPaperRecordPage.getRecords(), memberPaperRecordPage.getTotal());
    }

    @Override
    public List<AppMemberErrorQuestionChapterRespVO> getMemberErrorQuestionChapterList(Long courseId) {
        return null;
    }

    @Override
    public List<Long> getCurrentMemberCollectQuestionIdList(Long courseId) {
        Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
        return memberQuestionRecordMapper.getCurrentMemberCollectQuestionIdListByCourseId(loginUserId, courseId);
    }

    @Override
    public List<MemberPaperErrorRecordDO> listMaxSeqMemberPaperErrorRecordByMemberId(Long memberId) {
        return null;
    }

    @Override
    public List<Long> getCurrentMemberQuestionIdList(AppMemberPaperListReqVO reqVO) {
        List<Long> questionIds = new ArrayList<>();
        Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
        List<PersonalPaperDO> personalPaperDOS = personalPaperMapper.selectList(new LambdaQueryWrapper<PersonalPaperDO>()
                .eq(PersonalPaperDO::getMemberId, loginUserId)
                .eq(PersonalPaperDO::getCarType, reqVO.getCarType())
                .eq(PersonalPaperDO::getSubject, reqVO.getSubject()));
        if (CollUtil.isNotEmpty(personalPaperDOS)) {
            questionIds = personalPaperDOS.stream().map(PersonalPaperDO::getQuestionId)
                    .collect(Collectors.toList());
        } else {
            int randomBatchNum = RandomUtil.randomInt(1, 10);
            List<AppStandardPaperQuestionRespVO> standardPaperQuestionIdList
                    = standardPaperMapper.getStandardPaperQuestionIdList(reqVO, randomBatchNum);
            Map<Integer, List<AppStandardPaperQuestionRespVO>> collectMap = standardPaperQuestionIdList.stream()
                    .collect(Collectors.groupingBy(AppStandardPaperQuestionRespVO::getQuestionType));
            List<AppStandardPaperQuestionRespVO> judgeList = collectMap.get(QuestionTypeEnum.JUDGE.getType());
            if (CollUtil.isNotEmpty(judgeList)) {
                questionIds.addAll(judgeList.stream()
                        .sorted(Comparator.comparing(AppStandardPaperQuestionRespVO::getSortNo))
                        .map(AppStandardPaperQuestionRespVO::getId).collect(Collectors.toList()));
            }
            List<AppStandardPaperQuestionRespVO> singleList = collectMap.get(QuestionTypeEnum.SINGLE.getType());
            if (CollUtil.isNotEmpty(singleList)) {
                questionIds.addAll(singleList.stream()
                        .sorted(Comparator.comparing(AppStandardPaperQuestionRespVO::getSortNo))
                        .map(AppStandardPaperQuestionRespVO::getId).collect(Collectors.toList()));
            }
            List<AppStandardPaperQuestionRespVO> multipleList = collectMap.get(QuestionTypeEnum.MULTIPLE.getType());
            if (CollUtil.isNotEmpty(multipleList)) {
                questionIds.addAll(multipleList.stream()
                        .sorted(Comparator.comparing(AppStandardPaperQuestionRespVO::getSortNo))
                        .map(AppStandardPaperQuestionRespVO::getId).collect(Collectors.toList()));
            }
        }
        return questionIds;
    }

}
